function $(item){
    return document.querySelector(item)
}

function ajax_get(option){
    let xhr=new XMLHttpRequest()
    if(option.params){
        let str='?'
       for(let key in option.params){
        str+=`${key}=${option.params[key]}`
        str+='&'
       }
       str=str.slice(0,-1)
       xhr.open('get',option.url+str)
    }else{
        xhr.open('get',option.url)
    }
    
    xhr.onreadystatechange=()=>{
        if(xhr.readyState===4){
            if(xhr.status===200){
                option.success&&option.success(xhr.responseText)
            }else{
                option.error&&option.error()
            }

        }
    }
    xhr.send()
}

function ajax_post(option) {
    let xhr = new XMLHttpRequest()
    xhr.open('post', option.url)
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded')
    xhr.onreadystatechange = () => {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                option.success && option.success(xhr.responseText)
            } else {
                option.error && option.error()
            }
        }
    }
    if (option.params) {
        let str = ''
        for (let key in option.params) {
            str += `${key}=${option.params[key]}`
            str += '&'
        }
        str = str.slice(0, -1)
        xhr.send(str)
    } else {
        xhr.send()
    }
}